/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.base.web.taccount;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.base.entity.taccount.Taccount;
import com.jeesite.modules.base.service.taccount.TaccountService;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 会计科目Controller
 * @author shengbin
 * @version 2021-03-29
 */
@Controller
@RequestMapping(value = "${adminPath}/base/taccount/taccount")
public class TaccountController extends BaseController {

	@Autowired
	private TaccountService taccountService;
	@Autowired
    private UserService userService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Taccount get(String accountId, boolean isNewRecord) {
		return taccountService.get(accountId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("base:taccount:taccount:view")
	@RequestMapping(value = {"list", ""})
	public String list(Taccount taccount, Model model) {
        model.addAttribute("listUser", userService.findList(new User()));
        model.addAttribute("taccount", taccount);
		return "modules/base/taccount/taccountList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("base:taccount:taccount:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<Taccount> listData(Taccount taccount, HttpServletRequest request, HttpServletResponse response) {
		taccount.setPage(new Page<>(request, response));
		Page<Taccount> page = taccountService.findPage(taccount);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("base:taccount:taccount:view")
	@RequestMapping(value = "form")
	public String form(Taccount taccount, Model model) {
        model.addAttribute("listUser", userService.findList(new User()));
        model.addAttribute("taccount", taccount);
		return "modules/base/taccount/taccountForm";
	}

	/**
	 * 查看表单详情
	 */
	@RequiresPermissions("base:taccount:taccount:view")
	@RequestMapping(value = "detail")
	public String detail(Taccount taccount, Model model) {
        model.addAttribute("listUser", userService.findList(new User()));
        model.addAttribute("taccount", taccount);
		return "modules/base/taccount/taccountDetail";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("base:taccount:taccount:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Taccount taccount) {
		taccountService.save(taccount);
		return renderResult(Global.TRUE, text("保存会计科目成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("base:taccount:taccount:delete")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(Taccount taccount) {
		taccountService.delete(taccount);
		return renderResult(Global.TRUE, text("删除会计科目成功！"));
	}
	
}